package xuegao.study.mall.admin.feign;

import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
import xuegao.study.mall.common.api.CommonPage;
import xuegao.study.mall.common.api.CommonResult;
import xuegao.study.mall.common.model.ums.UmsMenu;
import xuegao.study.mall.common.model.ums.UmsResource;
import xuegao.study.mall.common.model.ums.UmsRole;

import java.util.List;
import java.util.Map;

@FeignClient(contextId = "role", name = "study-rbac-service", path = "/rbac/role")
public interface UmsRoleClient {

    @ApiOperation("增加角色")
    @PostMapping("/add")
    CommonResult<Integer> add(@RequestBody UmsRole umsRole);

    @ApiOperation("更新角色")
    @PostMapping("/update/{id}")
    CommonResult<Integer> update(@PathVariable("id") Long id, @RequestBody UmsRole umsRole);

    @ApiOperation("删除角色")
    @DeleteMapping("/delete/{id}")
    CommonResult<Integer> deleteRole(@PathVariable("id") Long id);

    @ApiOperation("角色列表查询")
    @GetMapping("/list")
    CommonResult<CommonPage<UmsRole>> listRole(
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
            @RequestParam(value = "name", defaultValue = "") String name);

    @ApiOperation("查询所有角色")
    @GetMapping("/listAll")
    CommonResult<List<UmsRole>> listAll();

    @ApiOperation("根据adminId获取角色列表")
    @GetMapping("/getAdminRoles")
    List<UmsRole> getRoleByUserId(@RequestParam Long adminId);

    @ApiOperation("查询该角色菜单列表")
    @GetMapping("/listMenu/{roleId}")
    CommonResult<List<UmsMenu>> listMenu(@PathVariable("roleId") Long roleId);

    @ApiOperation("查询该角色资源列表")
    @GetMapping("/listResource/{roleId}")
    CommonResult<List<UmsResource>> listResource(@PathVariable("roleId") Long roleId);

    @ApiOperation("给角色分配菜单")
    @PostMapping("/allocMenu")
    CommonResult<Integer> allocMenu(@RequestParam Long roleId, @RequestParam List<Long> menuIds);

    @ApiOperation("给角色分配资源")
    @PostMapping("/allocResource")
    CommonResult<Integer> allocResource(@RequestParam Long roleId, @RequestParam List<Long> resourceIds);

    @ApiOperation("角色资源映射列表")
    @GetMapping("/initResourceRolesMap")
    CommonResult<Map<String, List<String>>> initResourceRolesMap();
}
